// doorwheel.txt -  A wheel that opens nearby gates. When it is searched, asks if the
// party wants to turn it. if they do, swaps up to 2 terrain spots. 

// (When a terrain type is defined, you can set a swap terrain type for
// is, a terrain type that it changes to if it is opened/closed. For
// example, a closed gate's swap terrain is an open gate.

// Memory Cells - 
//   0,1 - The x,y coordinated of a gate this wheel opens. If both are left at 0, doesn't
//     do anything.
//   2,3 - The x,y coordinates of a second gate this wheel opens. If both are left at 0, doesn't
//     do anything.
//   4,5 -  Coordinates for a stuff done flag. If these are 0 and 0, ignored. Otherwise,
//     when the lever is pulled, if the stuff done flag is 0, it becomes 1, and if the flag
//     is non-zero, it becomes 0.
//   6 - Total of strength that needs to be in the party to turn the wheel.

beginterrainscript; 

variables;

	short choice;
body;

beginstate INIT_STATE;

		
	break;

beginstate START_STATE;
break;

beginstate SEARCH_STATE;
	reset_dialog();
	add_dialog_str(0,"This is a large wooden wheel. A chain is wrapped around it several times and then disappears through a hole in the floor.",0);
	add_dialog_choice(0,"Leave the wheel alone.");
	add_dialog_choice(1,"Try to turn it.");
	choice = run_dialog(0);
	if (choice == 1)
		end();
	
	if (get_skill_total(0) < get_memory_cell(6)) {
		message_dialog("You try to turn the wheel, but it is too large and too stuck. You aren't strong enough to budge it.","");
		end();
		}
		
	flip_terrain(my_loc_x(),my_loc_y());
	play_sound(99);
	print_str_color("You hear the sounds of grinding gears and the chain",2);
	print_str_color("  scraping over stone.",2);

	if ((get_memory_cell(0) > 0) || (get_memory_cell(1) > 0)) 
		flip_terrain(get_memory_cell(0),get_memory_cell(1));

	if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0)) 
		flip_terrain(get_memory_cell(2),get_memory_cell(3));

	if ((get_memory_cell(4) > 0) || (get_memory_cell(5) > 0)) {
		if (get_flag(get_memory_cell(4),get_memory_cell(5)) == 0)
			set_flag(get_memory_cell(4),get_memory_cell(5),1);
			else set_flag(get_memory_cell(4),get_memory_cell(5),0);
		}
break;
